entry: Set up text drag icon within drag_begin()
authorCarlos Garnacho <carlosg@gnome.org>
Thu, 21 May 2015 09:34:58 +0000 (11:34 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Tue, 26 May 2015 16:05:36 +0000 (18:05 +0200)
the drag_begin() vmethod is meant for this, and the internal DnD code
will set up a drag icon if ::drag_begin didn't do so, which means
we are first getting a "default" icon, and then replacing it with the
text surface.

This is completely harmless in X11, but causes issues on wayland as
the DnD icon window is expected to remain unchanged during DnD there.

https://bugzilla.gnome.org/show_bug.cgi?id=748763

gtk/gtkentry.c

index 6668da678bcc36e8a4d5cfdea0a683c2a512be35..62e3c8c4e844322560d1355bd983069350df8a0a 100644 (file)
@@ -4640,39 +4640,21 @@ gtk_entry_drag_gesture_update (GtkGestureDrag *gesture,
         {
           gint *ranges;
           gint n_ranges;
-          GdkDragContext *context;
           GtkTargetList  *target_list = gtk_target_list_new (NULL, 0);
           guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
-          gchar *text = NULL;
-          cairo_surface_t *surface;
           guint button;
 
           gtk_target_list_add_text_targets (target_list, 0);
 
-          text = _gtk_entry_get_selected_text (entry);
-          surface = _gtk_text_util_create_drag_icon (widget, text, -1);
-
           gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
-          cairo_surface_set_device_offset (surface,
-                                           -(priv->drag_start_x - ranges[0]),
-                                           -(priv->drag_start_y));
 
           button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
-          context = gtk_drag_begin_with_coordinates (widget, target_list, actions,
-                                                     button, (GdkEvent*) event,
-                                                     priv->drag_start_x + ranges[0],
-                                                     priv->drag_start_y);
+          gtk_drag_begin_with_coordinates (widget, target_list, actions,
+                                           button, (GdkEvent*) event,
+                                           priv->drag_start_x + ranges[0],
+                                           priv->drag_start_y);
           g_free (ranges);
 
-          if (surface)
-            gtk_drag_set_icon_surface (context, surface);
-          else
-            gtk_drag_set_icon_default (context);
-
-          if (surface)
-            cairo_surface_destroy (surface);
-          g_free (text);
-
           priv->in_drag = FALSE;
 
           gtk_target_list_unref (target_list);
@@ -9868,6 +9850,7 @@ gtk_entry_drag_begin (GtkWidget      *widget,
 {
   GtkEntry *entry = GTK_ENTRY (widget);
   GtkEntryPrivate *priv = entry->priv;
+  gchar *text;
   gint i;
 
   for (i = 0; i < MAX_ICONS; i++)
@@ -9886,9 +9869,30 @@ gtk_entry_drag_begin (GtkWidget      *widget,
               gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
 
               g_object_unref (pix);
+              return;
             }
         }
     }
+
+  text = _gtk_entry_get_selected_text (entry);
+
+  if (text)
+    {
+      gint *ranges, n_ranges;
+      cairo_surface_t *surface;
+
+      surface = _gtk_text_util_create_drag_icon (widget, text, -1);
+
+      gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
+      cairo_surface_set_device_offset (surface,
+                                       -(priv->drag_start_x - ranges[0]),
+                                       -(priv->drag_start_y));
+      g_free (ranges);
+
+      gtk_drag_set_icon_surface (context, surface);
+      cairo_surface_destroy (surface);
+      g_free (text);
+    }
 }
 
 static void